###############################################################################
# SuperLinks                                                                  #
# Copyright (c) 2000-2007 Greg Nolle (http://greg.nolle.co.uk)                #
###############################################################################
# This program is free software; you can redistribute it and/or modify it     #
# under the terms of the GNU General Public License as published by the Free  #
# Software Foundation; either version 2 of the License, or (at your option)   #
# any later version.                                                          #
#                                                                             #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   #
# more details.                                                               ##                                                                             #
# You should have received a copy of the GNU General Public License along     #
# with this program; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 #
###############################################################################
# ControlPanel/Output/Categories.pm.pl -> Categories module                   #
###############################################################################
# DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                         #
###############################################################################
package Skin::CP::Categories;

BEGIN { require "System.pm.pl"; import System qw($SYSTEM); }
BEGIN { require "General.pm.pl"; import General qw($GENERAL); }
require "Standard.pm.pl";
require "Tables.pm.pl";

use strict;

sub new {
  my ($class) = @_;
  my $self    = {};
  return bless ($self, $class);
}

sub DESTROY { }

###############################################################################
# show subroutine
sub show {
  my $self = shift;
  my %in = ("input" => {}, @_);

  #----------------------------------------------------------------------#
  # Printing page...                                                     #

  my @Fields = (
    {
      title     => "Del",
      width     => "1",
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => $f->CheckBox(name => "CID", items => [{ value => $r->{'ID'} }]) };
      }
    },
    {
      title     => "ID",
      width     => "45",
      sort      => "ID",
      nowrap    => 1,
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => $r->{'ID'} };
      }
    },
    {
      title     => "Title",
      width     => "65%",
      sort      => "FULL_TITLE",
      main      => 1,
      template  => sub{ my ($s, $d, $f, $r) = @_;
        if ($SL::QUERY{'OneLevel'}) {
          return { body => "<b><a href=\"".$s->URL(Root => $r->{'ID'})."\">$r->{'TITLE'}</a></b><br>$r->{'DESCRIPTION'}" };
        } else {
          return { body => "<b><a href=\"$SYSTEM->{'SCRIPT_URL'}?CP=1&action=ModifyCategory&CID=$r->{'ID'}&Referer".$SL::CGI->escape($s->URL())."&SID=$SL::ADMIN{'SID'}\">$r->{'FULL_TITLE'}</a></b><br>$r->{'DESCRIPTION'}" };
        }
      }
    },
    {
      title     => "Resources",
      width     => "100",
      nowrap    => 1,
      sort      => "RESOURCES",
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => $r->{'RESOURCES'} };
      }
    },
    {
      title     => "",
      width     => "35%",
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => $d->TableToolbar(
          items => [
            { type => "divider" },
            { type => "icon", url => "$SYSTEM->{'SCRIPT_URL'}?action=Category&CID=$r->{'ID'}", target => "_blank", icon => "Toolbar/view.gif", caption => "View" },
            { type => "icon", url => "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=ModifyCategory&CID=$r->{'ID'}&Referer=".$SL::CGI->escape($s->URL())."&SID=$SL::ADMIN{'SID'}", icon => "Toolbar/modify.gif", caption => "Modify" },
            { type => "icon", url => "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=RemoveCategories&CID=$r->{'ID'}&Referer=".$SL::CGI->escape($s->URL())."&SID=$SL::ADMIN{'SID'}", icon => "Toolbar/remove.gif", caption => "Remove" },
            { type => "icon", url => "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=Resources&OneLevel=1&Root=$r->{'ID'}&SID=$SL::ADMIN{'SID'}", icon => "Toolbar/resources.gif", caption => "Resources" }
          ]
        ) };
      }
    }
  );    

  my $Tables = Tables->new();
  
  return $Tables->Build(
    header      => "Categories",
    categories  => $in{'input'}->{'CATEGORIES'},
    records     => $in{'input'}->{'DISPLAY_CATEGORIES'},
    pages       => $in{'input'}->{'PAGES'},
    fields      => \@Fields,
    backup_row  => 1,
    del_field   => "CID",
    levels      => 1,
    hiddens     => [
      { name => "Referer", value => $Tables->URL() },
      { name => "action", value => "RemoveCategories" },
      { name => "CP", value => "1" },
      { name => "SID", value => $SL::ADMIN{'SID'} }
    ],
    toolbar     => [
      { type => "divider" },
      { type => "icon", url => "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=CreateCategory&Referer=".$SL::CGI->escape($Tables->URL())."&SID=$SL::ADMIN{'SID'}", icon => "Toolbar/new.gif", caption => "New" }
    ]
  );
}

1;